package com.jmb.api.web.controller.login;

import com.jmb.api.common.login.LoginUser;
import com.jmb.api.common.login.LoginUserHolder;
import com.jmb.api.common.result.Result;
import com.jmb.api.common.utils.JwtUtil;
import com.jmb.api.common.utils.LoginUserInfo;
import com.jmb.api.entity.LogInfoVo;
import com.jmb.api.vo.Login.LoginVo;
import com.jmb.api.vo.user.UserInfoVO;
import com.jmb.api.web.service.UserService;
import io.jsonwebtoken.Claims;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Tag(name = "登录")
@RequestMapping("/web")
@RestController
public class LoginController {
    @Autowired
    private UserService userService;
    @Operation(summary = "登录")
    @PostMapping("/login")
    public Result login(@RequestBody @Valid LoginVo loginVo){
        log.info("登录参数 {}", loginVo);
        String token = userService.login(loginVo);
        log.info("登录返回 {}", token);
        // 我现在想把返回的token，让UserService.getLoginUserInfo方法使用
        LogInfoVo loginUserInfo = userService.getLoginUserInfoToken(token);
        log.info("登录用户信息 {}", loginUserInfo);
        return Result.ok(loginUserInfo);

    }

}
